package com.heima.bos.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.activiti.engine.ProcessEngine;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.heima.bos.dao.DaoInter;
import com.heima.bos.dao.WorkordermanageDaoInter;
import com.heima.bos.domain.Workordermanage;
@Service
@Transactional
public class WorkordermanageService extends BaseService<Workordermanage>{
	@Resource
	private WorkordermanageDaoInter workordermanageDao;
	@Resource
	private ProcessEngine processEngine;
	/**
	 * 启动工作单
	 * @param id
	 */
	public void start(String id) {
		//获取工作单
		Workordermanage workordermanage = workordermanageDao.findById(id);
		workordermanage.setStart("1");
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("业务数据", workordermanage);
		String processDefinedKey = "transfer";
		processEngine.getRuntimeService().startProcessInstanceByKey(processDefinedKey, variables);
	}
	/**
	 * 查询未启动的工作单
	 * @return
	 */
	public List<Workordermanage> findNoStartList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Workordermanage.class);
		criteria.add(Restrictions.eq("start", "0"));
		
		return workordermanageDao.findByCriteria(criteria);
	}
	@Override
	public DaoInter<Workordermanage> getDao() {
		return workordermanageDao;
	}
}
